package app.keter.controller;

import com.jfinal.kit.JsonKit;
import app.keter.secruity.JwtUserDetails;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WhoamIController {

    @RequestMapping(value = "/api/me", method = RequestMethod.GET)
    public String me() throws AuthenticationException {
        JwtUserDetails principal = (JwtUserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return JsonKit.toJson(principal);
    }
}


